﻿using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MvcSample.Infrastructure.TagHelpers
{

    /// <summary>
    /// Danger replace tag helper.
    /// </summary>
    [HtmlTargetElement(Attributes = "danger-replace")]
    public class DangerReplaceTagHelper
        : TagHelper
    {
        public string DangerReplace { get; set; }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            //output.Attributes.TryGetAttribute("danger-replace", out TagHelperAttribute attr);
            //var val = attr.Value.ToString();

            //var equaled = val == DangerReplace;

            //var content = output.Content.GetContent();

            var tagHelperContent = await output.GetChildContentAsync();
            var content = tagHelperContent.GetContent();

            output.TagName = "p";
            output.Attributes.SetAttribute("class", DangerReplace);
            output.Content.SetContent(content);
        }
    }
}
